package com.mjh.action;

import org.apache.log4j.Logger;
import com.opensymphony.xwork2.ActionSupport;
import com.mjh.bean.ArticleDetail;
import com.mjh.comm.Constant;
import com.mjh.manager.ArticleDetailManager;
import com.mjh.manager.ArticleManager;

public class ArticleDetailAction extends ActionSupport{

	private static final long serialVersionUID = 1L;
	
	public static Logger log = Logger.getLogger(ArticleDetailAction.class);
	
	private ArticleDetailManager detailManager = new ArticleDetailManager();
	
	private ArticleManager articleManager = new ArticleManager();
	
	private ArticleDetail articleDetail;
	
	private int result;
	
	/**
	 * 添加文章内容
	 * @return
	 */
	public String add(){
		this.result = detailManager.addArticleDetail(this.articleDetail);
		if(this.result > 0){
			articleManager.updateaArticleIndexStatus(this.articleDetail.getArticleId());
		}
		return SUCCESS;
	}
	/**
	 * 修改文章内容
	 * @return
	 */
	public String edit(){
		this.result = detailManager.editArticleDetail(this.articleDetail);
		if(this.result > 0){
			articleManager.updateaArticleIndexStatus(this.articleDetail.getArticleId());
		}
		return SUCCESS;
	}
	/**
	 * 删除文章内容
	 * @return
	 */
	public String del(){
		if(this.articleDetail.getId() != 0){
			this.result = detailManager.delDetail(this.articleDetail);
			if(this.result > 0){
				articleManager.updateaArticleIndexStatus(this.articleDetail.getArticleId());
			}
		} else {
			this.result = Constant.FAIL;
		}
		return SUCCESS;
	}

	public int getResult() {
		return result;
	}

	public void setResult(int result) {
		this.result = result;
	}

	public ArticleDetail getArticleDetail() {
		return articleDetail;
	}

	public void setArticleDetail(ArticleDetail articleDetail) {
		this.articleDetail = articleDetail;
	}
}
